<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>layuiAdmin 后台管理员</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
	</head>
	<body ng-app="app" ng-controller="listContextController">

		<div class="layui-fluid">
			<div class="layui-card">

				<div class="layui-card-body">
					<div style="padding-bottom: 10px;">

						<button class="layui-btn layuiadmin-btn-admin" data-type="add">添加</button>
					</div>
					<table class="layui-table">

						<thead>
							<tr class="layui-bg-red">
								<th>用户名</th>
								<th>密码</th>
								<th>权重</th>
								<th>状态：1为启动,0为关闭</th>
								<th>创建时间</th>
								<th>delete</th>
								<th>修改状态</th>
							</tr>
						</thead>
						<tbody>

							<tr ng-repeat='admin in adminlist'>
								<td>{{admin.userName}}</td>
								<td>{{admin.passWord}}</td>
								<td>{{admin.widthRule}}</td>
								<td>{{admin.stauts}}</td>
								<td>{{admin.createTime}}</td>
								<td><button type="button" class="layui-btn layui-btn-sm layui-btn-danger" ng-click="deleteAdmin(admin.aid)">删除</button></td>
								<td><button type="button" class="layui-btn layui-btn-sm layui-btn-blue" ng-click="updateAdminStauts(admin.aid)">停用/启用</button></td>
							</tr>
						</tbody>
					</table>


				</div>
			</div>
		</div>
		<script src="../../../layuiadmin/jquery/jquery-1.11.1.min.js"></script>
		<script src="../../../layuiadmin/url.js"></script>
		<script src="../../../layuiadmin/jquery/angular.js"></script>
		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script>
			layui.config({
				base: '../../../layuiadmin/'
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'useradmin', 'table'], function() {
				var $ = layui.$,
					form = layui.form,
					table = layui.table;



				//事件
				var active = {
					batchdel: function() {
						var checkStatus = table.checkStatus('LAY-user-back-manage'),
							checkData = checkStatus.data; //得到选中的数据

						if (checkData.length === 0) {
							return layer.msg('请选择数据');
						}

						layer.prompt({
							formType: 1,
							title: '敏感操作，请验证口令'
						}, function(value, index) {
							layer.close(index);

							layer.confirm('确定删除吗？', function(index) {

								table.reload('LAY-user-back-manage');
								layer.msg('已删除');
							});

						});
					},
					add: function() {
						layer.open({
							type: 2,
							title: '添加管理员',
							content: 'adminform.html',
							area: ['420px', '420px'],
							 
							yes: function(index, layero) {
 
							}
						});
					}
				}
				$('.layui-btn.layuiadmin-btn-admin').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});
			});
		</script>

		<script>
			var app = angular.module('app', []);
			app.controller('listContextController', ['$scope', '$http', function($scope, $http) {
				$scope.selectAdminList = function() {
					$http({
						method: 'GET',
						url: applicationUrl + 'adminsys/api/list',
						headers: {
							"Content-Type": 'application/x-www-form-urlencoded'
						},
					}).success(function(result) {
						$scope.adminlist = result.data;
					}).error(function(data, status) {
						console.log(" ");
					});
				};
				//加载用户信息
				$scope.selectAdminList();
				$scope.deleteAdmin = function(aid) {
					var flg = confirm('确定删除吗？');
					if (flg == true) {
						 var token = window.sessionStorage.getItem('tokens');
						  if (token == null) {
						      window.location.href = "../views/user/login.html";
						  }
						var token = JSON.parse(token);
						console.log("mid="+token);
						$http({
							method: 'POST',
							url: applicationUrl + 'adminsys/api/delete',
							headers: {
								"Content-Type": 'application/x-www-form-urlencoded'
							},
							params: {
								aid: aid,
								token:token
							},
						}).success(function(result) {
							console.log(result.msg);
							if(result.code==500){
								alert(result.msg);
							}else{
								$scope.selectAdminList();
							} 
						}).error(function(data) {
							console.log(data);
						});
					}

				};
				
				$scope.updateAdminStauts = function(aid) {
					var flg = confirm('确定更改吗？');
					if (flg == true) {
						 var token = window.sessionStorage.getItem('tokens');
						  if (token == null) {
						      window.location.href = "../views/user/login.html";
						  }
						var token = JSON.parse(token);
						console.log("token="+token);
						$http({
							method: 'POST',
							url: applicationUrl + 'adminsys/api/updateStauts',
							headers: {
								"Content-Type": 'application/x-www-form-urlencoded'
							},
							params: {
								aid: aid,
								token:token
							},
						}).success(function(result) {
							console.log(result.msg);
							if(result.code==500){
								alert(result.msg);
							}else{
								$scope.selectAdminList();
							} 
						}).error(function(data) {
							console.log(data);
						});
					}
				
				};

			}]);
		</script>
	</body>
</html>
